<%-- index page, registration page. --%>

<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%-- Error page specify. --%>
<%@ page errorPage="WEB-INF/errorpage.jsp"%>

<%-- Java bean. --%>
<%@ page import="com.kha.Trainee"%>

<!DOCTYPE html>
<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Trainee Registration</title>
<link rel="stylesheet" type="text/css" href="vendor/css/bootstrap.css">

</head>

<body>

	<div class="navbar navbar">
		<div class="navbar-inner">

			<div class="container">
				<a class="brand" href="#">Trainee Registration</a>
			</div>

		</div>
	</div>

	<div class="container">

		<%-- Check input validation from validate.jsp.--%>

		<jsp:include page="WEB-INF/action/validate.jsp">
			<jsp:param value='<%=request.getParameter("txtHidden")%>'
				name="txtHidden" />
		</jsp:include>

		<%
			// Get bean from session.
			Trainee trainee = (Trainee) session.getAttribute("trainee");
		%>

		<%
		
			// Redirect to trainees.jsp in certain circumstances.
			if (trainee != null && trainee.isValid() == true) {
				if (request.getParameter("update") == null) {
					response.sendRedirect("trainees.jsp");
				}
			}
		
		
		%>

		<!-- Form to input data. -->

		<form class="form-horizontal" method="post" action="index.jsp">

			<input type="hidden" value="input" name="txtHidden" />

			<div class="control-group">
				<label class="control-label" for="inputAccount">Account</label>
				<div class="controls">
					<input type="text" id="inputAccount" placeholder="your account"
						name="txtAccount"
						
						value=<%if (trainee != null) {
				out.print(trainee.getAccount());
			}%>>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label" for="inputFirstName">Firstname</label>
				<div class="controls">
					<input type="text" id="inputFirstName" placeholder="your firstname"
						name="txtFirstName"
						
						value=<%if (trainee != null) {
									out.print(trainee.getFirstname());
								}%>>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label" for="inputLastName">Lastname</label>
				<div class="controls">
					<input type="text" id="inputLastName" placeholder="your lastname"
						name="txtLastName"
						
						value=<%if (trainee != null) {
									out.print(trainee.getLastname());
								}%>>
				</div>
			</div>

			<div class="control-group">
				<label class="control-label" for="inputEmail">Email</label>
				<div class="controls">
					<input type="text" id="inputEmail" placeholder="your email"
						name="txtEmail"
						
						value=<%if (trainee != null) {
									out.print(trainee.getEmail());
								}%>>
				</div>
			</div>

			<div class="control-group">
				<div class="controls">
					<button type="submit" class="btn">Submit</button>
				</div>
			</div>

		</form>
	</div>

</body>
</html>